package com.sphd.Restaurant.activity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sphd.Restaurant.R;
import com.sphd.Restaurant.base.BaseActivity;
import com.sphd.Restaurant.model.Model;
import com.sphd.Restaurant.utils.AppManager;
import com.sphd.Restaurant.utils.Constants;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.pedant.SweetAlert.SweetAlertDialog;
import cn.pedant.checkup.CheckUpdate;

public class SettingActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_feedback)
    TextView tvFeedback;
    @BindView(R.id.tv_checkforupdates)
    TextView tvCheckforupdates;
    @BindView(R.id.tv_aboutus)
    TextView tvAboutus;
    @BindView(R.id.ll_loginout)
    LinearLayout llLoginout;
    @BindView(R.id.content_setting)
    RelativeLayout contentSetting;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        AppManager.getAppManager().addActivity(this);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        setToolBar(toolbar, "设置", true);
        toolbar.setNavigationOnClickListener(view -> AppManager.getAppManager().finishActivity(this));
    }

    @OnClick({R.id.tv_feedback, R.id.tv_checkforupdates, R.id.tv_aboutus, R.id.ll_loginout})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_feedback:
                startActivity(FeedbackActivity.class);
                break;
            case R.id.tv_checkforupdates:
                CheckUpdate checkUpdate = new CheckUpdate(context);
                checkUpdate.checkUp(Model.BASEURL+Model.UPDATA);
                break;
            case R.id.tv_aboutus:
                startActivity(AboutusActivity.class);
                break;
            case R.id.ll_loginout:
                new SweetAlertDialog(SettingActivity.this, SweetAlertDialog.WARNING_TYPE)
                        .setTitleText("系统提示")
                        .setContentText("是否退出当前账号?")
                        .setConfirmText("确定")
                        .setCancelText("取消")
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sweetAlertDialog) {
                                sweetAlertDialog.dismiss();
                                AppManager.getAppManager().delAllActivityExceptMain(SettingActivity.class);
                                remember.edit().remove(Constants.PWD).commit();
                                remember.edit().remove(Constants.ISLOGIN).commit();
                                remember.edit().remove(Constants.USERPHONE).commit();
                                Bundle bundle =new Bundle();
                                bundle.putInt(Constants.JUMPPAGE, 0);
                                startActivity(MainActivity.class, bundle);
                                AppManager.getAppManager().finishActivity(SettingActivity.class);
                            }
                        })
                        .showCancelButton(true)
                        .show();
                break;
        }
    }
}
